// xercesc Helping Library.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "xercescHelpingLibrary.h"
#include "XMLElement.h"
#include "XMLDocument.h"
using namespace xercescHelpingLibrary;

void DisplayElement(CXMLElement* element, string prefix = "")
{
	if (element==NULL)
	{
		cout<<"NULL Element";
		return;
	}
	cout<<prefix<<element->getName();
	if (element->hasValue())
		cout<<": "<<element->getStringValue();

	string m1 = element->getAttributeValue("Material1");
	string m2 = element->getAttributeValue("Material2");
	cout<<"  "<<m1<<"  "<<m2<<endl;

	vector<CXMLElement*>* vec = element->getChildElements();
	for(int i=0; i<vec->size(); i++)
	{
		CXMLElement* child = vec->at(i);
		DisplayElement(child, prefix + "\t");
	}
}

int _tmain(int argc, _TCHAR* argv[])
{
	xhlInitialize();

	CXMLDocument* doc1 = CXMLDocument::OpenDocument("sample.xml","sample.xsd");
	DisplayElement(doc1->GetRootElement());

	cout<<"done\n\n\n\n\n\n";
	CXMLElement* mat3 = doc1->getElementByAttribute("MaterialName","mat3");
	vector<CXMLElement*>* v =  mat3->getChildElements();
	for (unsigned int i = 0; i<v->size(); i++)
	{
		CXMLElement* e = v->at(i);
		DisplayElement(e);
	}
	mat3 = doc1->getElementByAttribute("MaterialName","mat3");
	DisplayElement(mat3);
	delete mat3;

	mat3 = doc1->getElementByAttribute("MaterialName","mat3");
	DisplayElement(mat3);
	delete mat3;

	mat3 = doc1->getElementByAttribute("MaterialName","mat3");
	DisplayElement(mat3);
	delete mat3;


	delete doc1;
	xhlTerminate();

	cout<<"Done\n\n";
	return 0;
}

